package emf2gwtbridge;

import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.codegen.ecore.genmodel.GenRuntimePlatform;
import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
import org.eclipse.emf.codegen.jet.JETEmitter;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.Monitor;

public class TransferObjectGen extends GenBaseGeneratorAdapter {
	protected static final JETEmitterDescriptor[] JET_EMITTER_DESCRIPTORS = {
			new JETEmitterDescriptor("Request.javajet",
					"emf2gwtbridge.generators.Request"),
			new JETEmitterDescriptor("Proxy.javajet",
					"emf2gwtbridge.generators.Proxy"),
			new JETEmitterDescriptor("Service.javajet",
					"emf2gwtbridge.generators.Service"), };

	@Override
	protected Diagnostic generateModel(Object object, Monitor monitor) {
		GenClass c = (GenClass) object;
		GenPackage p = c.getGenPackage();
		GenModel m = p.getGenModel();
		if (m.getRuntimePlatform() == GenRuntimePlatform.GWT) {
			JETEmitter request = getJETEmitter(JET_EMITTER_DESCRIPTORS, 0);
			JETEmitter proxy = getJETEmitter(JET_EMITTER_DESCRIPTORS, 1);
			JETEmitter service = getJETEmitter(JET_EMITTER_DESCRIPTORS, 2);
			generateJava(m.getModelDirectory(),
					GeneratorUtils.getRequestPackage(p),
					GeneratorUtils.getRequestClassName(c), request,
					new Object[] { c }, monitor);
			generateJava(m.getModelDirectory(),
					GeneratorUtils.getProxyPackage(p),
					GeneratorUtils.getProxyClassName(c), proxy,
					new Object[] { c }, monitor);
			generateJava(m.getModelDirectory(),
					GeneratorUtils.getServicePackage(p),
					GeneratorUtils.getServiceClassName(c), service,
					new Object[] { c }, monitor);
		}
		return Diagnostic.OK_INSTANCE;
	}
}
